Api getfields code cleanup