Another bunch of refactoring