Some refactoring

Which should fix a few things