added debug-lines, fixed 2 bugs that prevented the lookup handler from returning proper result