Fixes and refactorings.