Fixed some bugs, added while