Separated out  logic for finding the square under the mouse cursor.