An iterative improvement algorithm for coherent codes