refactors some code