rewrote as object-oriented code