Fix emit('end') to fire only once