Refactors code to new structures