fix up backend / remove vast amounts of duplicated code