Fix to button count

as button.length wasnt correct and was producing an undefined exception