Add error control and fix update_file call