A couple of bug fixes and cleanup