refactoring a bit