Finished code refactoring