Restructuring API code