modified for-loop