Refactor savefig code

Now it uses the export framework