Fixing 'depth' function