Refactorings and cleanups