added variable msglen switch, needs work still