Fixed ending bug