refactores some code