Fixed several bugs, and a compatability issue.