General refactor making various features paramatiseable and making plugins neater.