Complete code refactor in sketchpad.js and everything is working now!