Minor cleanups, refactorings and fixes