fix scope of some assignments; fix typo in lex.mat