fix #9, fix #8, fix #7, fix #4