Update code style, fix bugs