move mainloop to own file, rename some members