Improved API examples

Corrected examples in doc comments so they will work regardless of the context in which they are executed.