refactor and fix code style