optimize anylysis code