Increment j before checking if it needs to be reset