Code restructured to OOP style