Fixed several miscellaneous bugs.