safely opening files, reverting 5ba5d7a1cd1c28ee9ebfeb1461a73bd778a7c682