Fixed several major bugs.