fix #45 and a couple of related bugs