added prune version of the code