Refactor, simplify and document parsedir