fix some tests and bugs