More work in progress: fixed the duplicate path bug and some other fixes