seems to work except fails test case