fix #1, fix #2, fix #4