onEnd improvement