Updated loop for KEYS processing and use unpack() args instead of creating additional table