fixed #54, plus more fixes