It's a little hard to parse what this logic is. If it's possible to extract a well-named private method or two for the last two clauses, please do.