fixed bugs when wrapping around and the selector go outside of the grid