Code Review

Some bug fix and code improve