Convert 'int ndim' to 'size_t' throughout, fix many msvc compiler warnings