This is kind of confusing. Could you move these conditions to a helper method?