fixed bug to deal with null values