added param checking and dirname