min and max functions added