Add test for remove_empty_dirs, fix few bugs.