Adding tests and fixing a bug found with them.