magic optimization