ami: some optimizations