Added lval struct and error checking