Rename API functions and throw errors

Looks like you can reorder this to reduce code duplication