Small fixes and refactorings