add checks for file i/o