Minor cleanups and bug fixes