Completed open file function