refactoring slightly