Fixed bug with for-loop