Misc refactoring