Fixed bug where generate hash causes infinite loop