pruning and simplifying the code