Refactored the parser.
Made all objects serializable for I/O so that parsing is not needed
every time.