add helper function to get path. the code just from function "dispatch".