refactor and add #31 cases
fix #31