refactor and add tests for composite type support