FIX: Few bugs fixes.  Making deep copy of input and output that.