Replaced for-loop with method