Format out some redundant code in API handling