api request code cleanup