all working except main loop