added check for king's safety