major code overhaul/cleanup/optimization on sketchpad.js