added functionality to prevent object overlap inside the canvas