Better algorithm for cleaning the canvas