Minor refactorings and cleanups