close #42

close #39

Some code review, and fix some upgrade bugs