rewrote parsing to be a little clearer/readable