Lots of reindentation make this hard to follow. Did you just wrap a block in `if (isPageVisible()) {…}`?