Misc refactorings