[WIP/RFC] Fixes to API-related code

This PR is for fixing some problems on the code merged with #582