Fix api controller bugs