better lookahead function