fix #505, fix #504