I suggest splitting that up in 2-3 reflexes and dealing with the perf issue at a different level.