Minor adjustments to a few functions, and added a bit more testing.