rewrite code in oop paradigm