Improved code handling