Generalised a piece of code so it can be run with giga/wiki input more easily