try and write a more efficient parsing algorithm using just a single loop