factor out conversion logic