code getting hung on min function