added generate_hash and removed Rails-specific code