corrected calculation of payload size
corrections in window calculation, sequence number calculation and added debug output