Refactored for-loops