Circuit optimizer