Remove retain cycles and small refactorings.