A little cleanup and refactoring