The logic here works, but let's talk more abstractly about figuring out how to write it more simply