Fix possible bug with dirname