Prepare code for re-use

Pulled all dependencies out of the example app (main.c) file so that it can be dropped easily into other projects.