Fixed secure_check function