Fix broken logic and a quick test hack