Fixed a bug in directory handling