Avoid nested for-loop