bug fixes, more tests