Separate the logic out