Fix broken tests; do miscellaneous cleanup