simplify some codes into class