duality test and a bug fix.