refactor code and format