many small changes:
uses path
uses indexOf instead of search, to avoid confusing string with regex
minor tweaks and fixes