Main app loop