Fix build problems

Types can only be used when types are defined when types are known, e.g. the
header file included ...
Minor cosmetic changes

Aligned preprocessor defines, removed trailing white space and put
comments before the statement instead of the same line.
Minor optimizations

Reduce some unnecessary calls and shuffle code around.
Merge pull request #7 from matze/fix-build-and-style

Fix build and style