fix #1 and partial fix #2