if-else instead of ifs and removing the unneeded exception