Replace `main` with `loop`