Fixed some issues in redundant unsafe context issue