Rewrote code to be consistent with cartesian states