Refactored a lot of code.