Some possible minor bug fixes and code cleanups.