Refactored parsing code a bit, abstracted mostly for readability.
Better exception handling. Will add docstrings to functions.