restyle and refactor code