fix #163, thanks to @tkelman for the debugging work