Isolate setup into its own function
Make advance to next states a function
Extract finish-parsing into its own function