Code reorg

While reviewing the code and logic (which is excellent, btw), I tried to reorganize the code to make it easier to compile with a Makefile. Feel free to reject this pull request, or simply reuse some parts in your code.

I'd like to keep the master branch somewhat up to date with code we can compile. That would greatly help reviewing it.