updated with some control on null values