first part of stage 7a rewrite