Modified for-loop code just a bit