changes to compile with newer XCode / SDK
use unsigned ints to get defined overfow behavior