Fixed some important bugs