fixed some bugs in main simulator loop