rewrote code in Object Oriented style