I was seeing an issue where the buttons would show up and disappear, but it looks like better separation between UI and non-UI code took care of the problem. Removing the if.