safeCode to avoid loops