refactoring to break functions out and use callbacks