Intiate function as soon as button is pressed, not loop it over and over.

If the rest of the code is necessary

It probably is.