# ... [keep the previous functions and main loop] ...