Remove REST code

Cherry pick changes from #638 and apply some additional fixes.