Finish refactoring code