Refactor organization of code