Fixed some bugs for messages length