added a check for avoid operation on null