Added undo, optimized drawing code