added sort wrapping to Code function