Fix bugs with end string