Updated to work with dynamic buttons.