Updated class file to include checks for loop and listener

Event listener for button added and for loop