Fix and improve tests