Refactors some code