change max/min and error fixing