various cleanups of bugs discovered by using