adding tests and fixing a bug found