refactoring to make this a little nicer