improve types and null handling