I think the problem was a missing bracket!

Looks like one missing bracket was what was flexing. See if this works for you!