Got rid of global variable, changed cur to curPath for clarity