Refactors the code