refactored logging code (now closes on disconnect), added comments of things to do
fixed disconnect function - should really test this compiles before committing
Tidied up comments and old code - need to fix the main loop