add MaxDepth parameter to logging function
clean up logging in some functions