refactor.
use utility functions.
add CanvasData class.
refactor.
apply event handlers.
add painter handler.