Diff is hard to read, but basically I used early continues to reduce nesting