fix nil bug in protection code