moved stuff out of Json call back function