refactor of ifs