-Fix: allocation and freeing was a bit off.

while at it, we also allow both int and long types, and convert
accordingly in lookup()