General refactoring and a few more or less pointless unit tests