Refactor AMI creatino script