General refactoring/rearrangement