rewrite read file function