refactors the code