refactored out functions
added testing