WIP: Schema

The idea here is to go through all the user-facing functions and organize them into 3 sections.

 1 - Declare all local variables at the top
 2 - Check the arguments against a static schema
 3 - Perform the action being aware of early exits and cleanup of resources.

There are quite a few memory leaks that are only triggered by various error cases.  This refactor should fix most if not all of them.
no static here, and the next 3 lines