minor cleanup and a couple bug fixes