Clean up directory parsing. Untested.