fixed tests and a few bugs