refactored merge_dirs + cp_tree and fixed unit tests