fixed #272 and some other bug fixes.