added error check for ifs