reduced some if's nestings