Import some fixes from rapidsms_generic