Update tests, fix bugs