converted the entire algorithm into class structure