fix #211 and a bunch of other nits