gh-232 review fixes

Don't use sprintf/strncpy - they are unsafe from secure programming POV.
Remove trailing spaces. Use one empty line between function
definitions, not two. Put header guards before the licence, be nice
to the preprocessor. Put the main header file first in the implementation
file, this automatically checks that the header is self-sufficient.
Add comments. We don't use spaces before/after ( ) braces.