Removed off by one error resulting in extra loop iteration