Fix a few bugs for data retrieval in the API