code cleanup and remove dependency on dirent.h