remove duplication
beautify indentation
some renaming