Add several extra helper functions to reduce command count.
Fix a couple of buffer overflow issues.