Way too much code to wade through unless you can narrow it down.

Are you sure you are not making the common mistake of doing integer division? 9 / 2 = 4 not 4.5 and if you are doing something like...