Fix the logic so that it actually ignores invisible layers, not visible ones.