Fixed some bugs after testing