Some refactor and fix #12