optimized get_hash