Fix grid calculation inaccuracy.

Thanks to Daniel Koukola <dkoukola@gmail.com> for pointing out this bug.