Optimizing code between entity and player