modified to work with null values