Finished refactoring the code.