Refactored parsing algorithm.