Some minor changes and refactoring