Improved external code handling