Refactored canvas drawing code to a new object.