More robust makefile
Move a bunch of code into connection