fix message factory logic