lookabhead optimization added