Rewrite some codes, fix code style