Refactoring quite a lot. Very confusing...