added conditional checking