Restore hash

Refactored a bit, changed some other stuff.