code rewrited with classes