Debug statements and code cleanup

keep track of message length from the read instead of  using multiple
strlen()
better variable names
debug output cleanup
standardized the getMessage code in availableEvent and sendEvent in
preparation of functionalizing it