new stateful client works with headers
some comments added, new param variable and fixed header length