Backend refactor to cut down on duplicate code