fixing end bug