Changed Math.min call to outside the loop so as to split power evenly between inputs when more energy is requested than can be output