More debug statements, changed to size_t, and loop guards