finished parsing algorithm implementation