Fix in forging query to calculate query output length - closes issue #342