fixes for links to folders of different package instances:
- when resolve_local is used, fetch the correct index page, when target folder has an index page defined
- when resolve_local is used, avoid potential resolving loop
various code improvements:
- improve comments
- use better variable names
- remove dead code
- Package.lookup: make it am ad_instproc and make clear, it returns an integer