Improved the directory parsing