fixed some bugs and added a main