Extract logic from controller