Some minor cleanup and refactoring