I agree with you. First time I read this function I found the logic tricky to follow. But, I think I'd leave that for a next PR? I know my current logic works, and I'd rather just change one thing at a time.