refactor code for setting