Refactoring of directory sync