added maxSVal function, tested