Changed parsing algorithm, introducing Stream class