Move logic to listener