General refactoring/rearranging