fixed tests and found bugs