took out several strlen() calls out of the loop; replaced int's with size_t where needed