fix #138, fix #140, fix #149, fix #142, fix #143, fix #13, fix #144, fix #12, fix #145, fix #146, fix #147, fix #9, fix #7, fix #148