Rewrite directory content parsing. Fix #535 #519