some refactoring to clean up