Security improvement and minor fixes

Introducted checks on the messages chunks length