[IMPROVEMENT] Writing a button state detection function