I haven't thought this through, but it feels like this method can be simplified. I wouldn't worry about trying to though, just sharing my gut feeling.