General refactoring (part 5 of lots)