Added proper handling of nulls