Some bug fixes and some more tests added