Fixes a small looping error