Yeah, I think this could definitely use more refactoring. Obviously was bad to start with, but this is just nonsense to read.  I'm with you, not entirely sure whey there are so many `select {}` calls here to filter that array down.