The original snippet works fine, and therefore should require no attention from you. Rewriting it to use different constructs probably won't "optimize" it at all ... and is likely (as you saw) to make it stop working altogether and/or to become much more fragile. You are, if I may politely say, wasting your time.