I think I need to read a makefile tutorial.
Added reconnection and error handling. Moved wrapper stuff to its own file.