pull out pruning logic into its own module and split up complex method