Moved going up by basenames and going up by level into separate functions.
The %q format specifier is now used for escaping.
Small modifications.