Simplify by removing the loop and event handling