Fixed cachedir function