Rewrote in oo style.