Added scrollIntoView for onTopLayer function, which detects out-of-view top layer elements correctly. This is a major change to a infrastructure function however, so might create errors. Includes other bug fixes.