button loop now terminats after pressing a button