Beam parameter stabilization for the P2 experiment at MESA