working version, now works with array and hash lookups also