Clean up and implemented minimize and close