Improved and fixed normalizePathElements