merged two ifs on leave function in one