implements grid snapping