Fix type assertion in map and refactor unpackers