Add tests to cover issue #319
Fix bounds calculations