Fix bugs occurred when enter key is pressed