rewrite most lab5 scripts