Adding asserts in most places.

These are asserts for parameters. We still need to add select
asserts for entering functions that reference globals like
_layers and _resources.