Expanded test coverage, fixed bugs discoved by the new tests