missing header file for min and max; added <algorithm>