Move message generation code to client