Finished refactoring code