Fix lookup functions and some other problems