Changed few types around to avoid comparisons between signed and unsigned ints.