Streamlined hw6 code