Refactored buildPartitions to use recursion instead of stacks, and moved the dfs code to mask.go