Item9741: disentangled some spaghetti code



git-svn-id: http://svn.foswiki.org/trunk/core@17542 0b4bb1d4-4e5a-0410-9cc4-b2b747904278