Fix some bugs, pass tests locally