refactoring a little bit