Refactor some, add some more tests, add more parameters.