optimize margins