fixing onend issue