added deriv_R_phi, various cleanup