Made output argument optional and added optional x ranges