In this paper, we propose a new algorithm to find automatically the optimal ordering of a batch of refactorings in which to apply these refactorings. The algorithm detects implicit sequential dependencies, resolves conflicts between the different refactorings in the batch and minimizes the number of refactoring operations by removing the redundant ones. It is based on the semantics of a predefined set of fine-grain transformations (FGTs) to describe any refactoring, and relies on logic-based representations of the underlying UML model. The algorithm saves time and effort and uses several innovative techniques to improve the performance at the time of refactoring.