minor refactoring to clean up the code