rewrite functions using class