Better input truncation and length limiting