fix the end bug