Began the process refactoring the code to make it easier to understand.