Small refactorings and code cleanups