refactor code of if condition