cleaning API with null checking