refine code, add case class