started implementation of main loop (incomplete)