Fixed some bugs and made a few changes