improve code style, fix bugs