cleaned up more formating and moved some variables closer to where they are used
cleaned up more formating and moved some variables closer to where they are used; refactored horrible logging api
refactored; extracted function from main
refactored main function;extracted response loop
clean termination