In #27, I started to add some unit tests for functions in the executables. This uncovered a long-standing bug. Add as many more unit tests as is feasible to cover as much code as possible. (In the future, in a separate issue, I plan to implement code coverage reports).