Added client logging and refactored some code.