Add support for specifying the number of outputs.
TEST: add unit tests for a user-supplied number of outputs