Fixed min function