Fixed the ending bug