first round of fixes for making the code match the diagrams