refactor entity instance system