External API functions need to grab locks before performing internal database operations.

Untangle internal and external functions, to prevent recursive locks