Minor fixes and refactorings