refactoring a little