Fix internal memory tracking
Fix entity free functions