optimize hashfile function