passes many test cases (but started restructuring mod)