code to minimize