Proper check for currentMin/currentMax before prepending functions

This is the reorganized version of pull request #90.