Fix bug for buffer overrun and added logging of incoming buffer

Fix bug for buffer overrun and added logging of incoming buffer