fixed some bugs in main