fix #1, #2, #4