Added proper handling of null values.