refactored out some code