Memory fixes, lookup error handling

The lookup functionality now calls panic() on error, which is a universal
destructor, i.e. it makes sure all the allocated memory is released. At
least Valgrind is happy again.. :)