Implement min / max manually (b/c "apply" can cause stack overflow)
minVal fix