first pass at refactoring canvas code