Removed unnecessary loop and added debugging toggle.