Fix and improve unit tests