refactored code to avoid reinstantiating buttons