finished lex function