Moar tests + refactoring magic + optimisations