Refactor canvas into a standalone class.