refactor to use user-defined data type and class instances