Refactorate and set depth parameter.