works for all test cases now