A bit of pythonic approach.

Also it was throwing error if not output specified.