improve button input logic