rewrite datatype definitions and implementations