all code written, except min1~ min2