Better code organization, removed dead code