Cleaned up the main code a bit and also added a bit more logging to the NetworkHandler