fixed parsing algorithm