Degeneracy-corrected perturbation theory for electronic structure calculations