fix #507 and #506