Refactoring, cleanup, and adding admin functionality