Refactor HTML handling code into tested ns linkin.html