fit to coding rules and fix bugs