Cleanup of examples

Fixes some examples & catches errors everywhere.
Code cleanup.