A man who police say stabbed his estranged wife in front of her fifth-grade class entered the building after a student inside walked by a motion sensor that unlocked a door, the school's principal said.

The building's security system worked as designed, and it was only a coincidence that William Michael Layne was able to enter, Principal Kay Kern told the Portsmouth Daily Times in a story published Tuesday. She said the motion sensors are part of a fire safety system.

Layne was in the school Thursday for only two minutes, she said.

Just before he arrived at Notre Dame Elementary School, Layne, 56, stabbed a woman in an alley behind her home, police said. He then stabbed his schoolteacher wife, and after a three-hour standoff with police at his home, he apparently shot and killed himself, authorities said.

Christi Layne, 53, who had left her husband and had filed for divorce Jan. 25, remained at Cabell Huntington Hospital in Huntington, W.Va., on Tuesday morning, a nursing supervisor said.

Stephanie Loop, 22, who was attacked a few blocks from the school, was released from Grant Medical Center in Columbus on Saturday, the Daily Times reported. Loop's cousin, Chrissy Shepherd, has said that Layne considered Loop his girlfriend.

Students returned to the Roman Catholic school Monday for the first day of classes since the attack, with counseling services provided for students, teachers and parents. Kern said most children attended, with about three calling in sick.