Fixed issues mentioned by Xudong