Added Mainloop

Highly experimental, Feel free to reverse changes