moved variables into the function and move buttons to the top of the page