Add "safe math" functions for handling overflow/underflow