Operate on arrays when resolving relative paths

Instead of relying on do/while loops & regular expressions.