As gridSize is power of two it could be less one comparison.
Removed useless boolean variable.