Improve safety

Add exit.h for global exit point with message.
Make log function inline in header.
Check for null pointer an nonexisiting files.
Add underflow and wrong-subs tests.
Log a lot of things.