Fixes identified by the test suite

This pull request includes fixes for several issues revealed by the new test suite.