Extract methods and rename some variables to make the code cleaner. Use parameter max_buffer_size in the initialization of connection. Change-Id: Idc537816692adf64eb6b77ea02ca1e507cf2588b