refactor code and correct style