completed code refactoring