Refactor internal sd api to take the sd context.