Finally, provably working version. This needs a makefile.