Refactor on 'ended'