Implemented cases for button loop and added comments