[powerdebug 05/14] encapsulate the mainloop code