fixed some bugs in the main script