Refactored for consistency and fixed a root page bug