
688 So.2d 1285 (1997)
STATE of Louisiana
v.
Rodney L. SMITH.
No. CR96-1041.
Court of Appeal of Louisiana, Third Circuit.
February 5, 1997.
Robert Richard Bryant, Jr., Lake Charles, for State of Louisiana.
Andrew Michael Casanave, Eugene Bouquet, Lake Charles, for Rodney L. Smith.
Before SAUNDERS, PETERS and AMY, JJ.
PETERS, Judge.
The defendant, Rodney L. Smith, pled guilty to manslaughter and was sentenced to forty years at hard labor with the first five years being without benefit of probation, parole, *1286 or suspension of sentence. He appeals, contending that the sentence imposed was illegal.

DISCUSSION OF THE RECORD
The defendant was born on August 20, 1971, and is a resident of Houston, Texas. On September 2, 1991, while visiting friends in Lake Charles, Louisiana, he was approached by Teryl Glenn Labbe who informed him that he had been robbed of approximately four hundred dollars and some crack cocaine by David Bird. Labbe told the defendant and others that Bird had held a gun to his head and robbed him. He asked the defendant and the others present to help him get his property back. They agreed, and the group went to Room 403 at Motel 5 on East Broad Street in Lake Charles, where Labbe said Bird was staying with two females. The group knocked on the door, and it was answered by one of the females whom Labbe immediately started hitting. The rest of the group approached Bird, who was lying on the bed, and demanded that he return Labbe's money. Bird told them to get out, and they shot him. More than one person shot Bird, and the general consensus is that the defendant fired the first shot; however, he denies this. Bird was struck with approximately three bullets. The group left the hotel, and emergency medical personnel were called to the scene. Bird was taken to Lake Charles Memorial Hospital Emergency Room where he was pronounced dead. The Coroner's report lists the cause of death as a gunshot wound to the hip and abdomen.
The defendant was subsequently arrested and charged with first degree murder, a violation of La.R.S. 14:30. The state filed notice of its intent to seek the death penalty and notice of its intent to enhance the charges pursuant to La.Code Crim.P. art. 893.1. A plea bargain was reached whereby the defendant agreed to plead guilty to the lesser charge of manslaughter, a violation of La.R.S. 14:31. The parties jointly recommended a sentence of forty years at hard labor to the trial court. This recommendation was accepted by the trial court, and the defendant was sentenced to serve forty years at hard labor with the first five years being without benefit of probation, parole, or suspension of sentence.

OPINION
The defendant now appeals his conviction, contending that the trial court erred in imposing an illegal sentence, refusing to amend the illegal sentence, and stating that the proper lawful remedy for the illegal sentence was the withdrawal of his guilty plea.

Assignment of Error Number One
At the time of the commission of this crime, the maximum sentence for a violation of La.R.S. 14:31 was twenty-one years. The legislature amended the statute by Acts 1992, No. 306, § 1, to increase the maximum penalty to forty years at hard labor. Thus, the defendant was given the maximum penalty under the law as it existed at the time he was sentenced. The defendant contends that the sentence imposed amounts to the exercise of an ex post facto law in violation of La. Const. art. 1, § 23.
A defendant is to be tried and sentenced under the statute which was in effect at the time he committed the crime. State v. Bethley, 452 So.2d 367 (La.App. 1 Cir.1984). Ex post facto laws are prohibited by not only the Louisiana Constitution but also the United States Constitution. La. Const. art. I, § 23; U.S. Const. art. 1, §§ 9 & 10. This prohibition also applies to the enforcement of any enactment which changes the punishment to inflict a greater penalty for the crime than that which was authorized at the time it was committed. State v. Payne, 633 So.2d 701 (La.App. 1 Cir.1993), writ denied, 94-0291 (La.6/3/94); 637 So.2d 497. Thus, legislation which amends a criminal statute to increase the possible maximum penalty for violating the statute cannot be applied to someone convicted of committing a crime prior to the enactment of the legislation. In this case, the defendant shot the victim in September 1991 when the maximum penalty for manslaughter was a sentence of twenty-one years at hard labor. Thus, the trial court erred in imposing a sentence of forty years at hard labor. We therefore find that this assignment has merit.


*1287 Assignment of Error Number Two
The defendant next contends that the trial court erred in refusing to amend his illegal sentence.
When a sentencing court discovers that a sentence does not conform to an applicable penalty statute, it has a duty to correct the sentence to bring it into compliance with the applicable law. State v. Fraser, 471 So.2d 769 (La.App. 1 Cir.1985), rev'd on other grounds, 484 So.2d 122 (La.1986). In this case, the defendant's sentence did not conform to the applicable penalty provision, and thus, the trial court had a duty to amend his illegal sentence.

Assignment of Error Number Three
By his final assignment of error, the defendant contends that the trial court erred in stating that the only remedy available to the defendant was for him to withdraw his guilty plea. The language utilized by the trial court makes it extremely unclear what remedy it felt was available to the defendant. We do not believe that the only remedy available to the defendant was to withdraw his guilty plea. It is a long-standing rule of law that a defendant's position cannot be made worse because he chooses to exercise his right to appeal. If we were to find that the defendant was only entitled to withdraw his guilty plea, then he would be back to facing a conviction for first degree murder and the possibility of the death penalty. Clearly, the death penalty would be more detrimental to the defendant than the forty-year sentence he has appealed to this court.
An illegal sentence may be corrected at any time by the court that imposed the sentence or by the appellate court on review. La.Code Crim.P. art. 882. In this case, the trial court's sentence was not one of discretion in that it imposed the maximum sentence. For judicial efficiency and economy, we choose not to remand for resentencing. Rather, we amend the sentence pursuant to the authority granted by La.Code Crim.P. art. 882 to reflect the maximum sentence which could have legally been imposed on the defendanttwenty-one years at hard labor. See State v. Yancy, 93-2798 (La.5/31/96); 673 So.2d 1018.

DISPOSITION
For the foregoing reasons, we amend the defendant's sentence to a term of twenty-one years at hard labor.
AFFIRMED AS AMENDED.
AMY, J., concurs in vacating the sentence, dissents as to the remainder of the majority view, and would remand for resentencing.
