restructured with scratchpad