added missing close tags, reorg'd code to do proper mem-cached reloading