Finished refactoring of code