fix end reached bug