Bug fixes + refactorisation