Writing test_pa and correcting discovered bugs