Update tests and fix some bugs