add BrowseDir function and fix bugs.