replaced min and max functions with numpy equivalents