fixed some size_t types, added checks for <0 when casting from int to size_t