Code adjusted to work with larger number of parameters.