implemented button pressing logic.