added digest function, still some bugs