Test logic moved out of api code. More code deleted. Tests pass locally.