Small fixes and refactorings.