refactor and fix, #20