1. A method for code refactoring comprising: acquiring a code; identifying, using processing circuitry and based on a Markov decision process model, a refactoring sequence, wherein the refactoring sequence includes a plurality of refactoring steps to be applied to the code; identifying a plurality of states, each state representing a potential state of the code; identifying a plurality of actions, wherein each action corresponds to a refactoring step; determining transition probabilities using enumeration techniques wherein each transition probability represents the probability that the code transition from a current state to a subsequent state by taking an action from the plurality of actions that cause the transition to the subsequent state; determining a set of rewards, wherein each reward is associated with each of the transition probabilities; determining a refactoring policy that maximize a sum of rewards as a function of the plurality of states, the plurality of actions, the transition probabilities, and the set of rewards; and applying, using the processing circuitry, the plurality of refactoring steps according to the refactoring sequence to generate a refactored code.