refactor lookup script and make it an executable