improved message overflow checking