Added depth() and countNodes() plus helper methods