better usage of dirname for building path