refact and fix some bugs
Merge branch 'dev'