main loop is functional, yet buggy