reduce number of ifs and clearer comments