Improved case 3 code.