Fixing error in a next, missing if