Refactored the overly lengthing parsing function to be more easily tested and maintained