Restructured code to make it easier to stack APIs