Committed initial implementation of pruning. Has some problems.