Draft of mainloop