refactor engine to isolate lesson format code