Refactors a bit