Fix bugs in 359157b4fd45521e834500fb9364e7b8ed9213aa