Added dirname flexibility