It seems that the problem is not related to your solidity code, but the transaction's setup(gas/gas limit). Let me know if this helps you.
Rouhollah Joveini
- 498
- 1
- 3
- 16