lua: fix various bugs in the refcounting implementation. seems to fix luci and reduce...