Bug fixes and test suite improvements