Refactored the parsing to make it easier to read and use.