Several fixes for curdir() function