revised for multiple inputs and outputs