refactoring a lil bit