Below is my code for the problem:

```
ItoR = {
1: 'I',
4: 'IV',
5: 'V',
9: 'IX',
10: 'X',
40: 'XL',
50: 'L',
90: 'XC',
100: 'C',
400: 'CD',
500: 'D',
900: 'CM',
1000: 'M'
}
def convertItoR(number):
number_str = str(number)
number_len = len(number_str)
rom_str = ''
for i in range(number_len):
# Extracting the digit
digit = int(number_str(i))
position = number_len - i - 1
num_pos = digit * 10 ** position
print(num_pos)
# Converting digit to roman string
if num_pos in ItoR.keys():
rom_str += ItoR(num_pos)
elif digit > 1 and digit < 4:
first = 1 * 10 ** position
rom_str += ItoR(first) * digit
elif digit > 5 and digit < 9:
first = 1 * 10 ** position
fifth = 5 * 10 ** position
rom_str += ItoR(fifth) + ItoR(first) * (digit - 5)
print(rom_str)
return rom_str
```

Can it be optimized?