code rewrite with class