some cleanup, plus some final bug fixes