some refactoring and better directory synchronisation