huge refactorisation