Improved relativize and basename function.