changed first function using hashes instead of scalar variables.