Refactor engine to use immutable vectors