Thanks for the formatted code.
Why are you using a nested loop to get the coordinates of the mouse clicks?