added checking if result isn't empty

If result is empty _output function isn't unnecessary called.
test rewritten