Minor cleaning and refactoring