Some refactoring
Revert "Some refactoring", this was too slow

This reverts commit 6cca3bce94e97e345e82c8695bc55f96e40cb95e.