Minor improvements and refactoring