This code is very blocky (and concise). Might break it up a bit into smaller pieces to improve readability.