fix closed entity context issues
add null checks