moved the canvas focus code into a single function