Open file function optimize