Improved accuracy of snap to grid

After some few movements back and forth the snap to grid lost its accuracy. I've added some improvements to keep snap to grid consistent.