replaced if with try