function updated to accomodate any number of conditions