ROCKLAND — A Maine State Prison inmate already serving a 40-year sentence for killing an ex-girlfriend has pleaded no contest to using an electric guitar to fatally beat another prisoner to death last year.

Guy Hunnewell had previously pleaded insanity in connection with the June death of 57-year-old Alan Powell, but changed his plea to no contest Tuesday in Knox County Superior Court.

The 43-year-old Hunnewell was sentenced to life behind bars in Powell’s killing, a sentence that won’t start until he has completed his 40-year sentence for the 1997 slaying of the woman.

Authorities say the men were in the exercise area of the prison in Warren when Hunnewell beat Powell with the guitar. It’s not clear what prompted the assault.