Improve entity handling