find base directory in a better way