Added debugging and fixed connection reset issue