refactores some code.