Added support for locking
Use smaller storage types for limited size values
More efficient code for repeat counting on send