Fix bugs in accordance with the comments