Update tests and fix bugs