Rewrite from dictionary structure to classes