tweaked procedure to ignore null values