You've got a couple places where a comment specifies that a particular argument must be one of some small set of values. Have you considered `assert`ing these as part of the funtion body?