If the court finds in favor of the petitioner, it shall enter an appropriate order with respect to the judgment or sentence in the former proceedings, and any supplementary orders as to rearraignment, retrial, custody, bail, discharge, correction of sentence, or other matters that may be necessary and proper.