changed size_t to int for cross-platform