refactoring code from review