Add shared code moved out of engine