Fix bugs to make test pass