various enhancements, main loop added