fix #51 and minor fixes.