Fix some bug

Fix some bug. add a test case in the top of the comment.