move button size calculation to its local scope