Refactoring some code.
Fix some bugs.
End of implementing undo redo and rewriting controllers