Fix and improve unit test