Miscellaneous fixes

This script was used in a project and ended up having some work done on it that could be used upstream.

This pull request fixes a few API errors, intelligently deals with messages that are too long for Twilio, fixes a bug with some SMS clients, and some other stuff.

Check the commits for more information.