Removed deprecation warnings and started using std::min/std::max