More refactor and fix #8