Code factorisation, and better error message when file not found.