Implemented this TODO note and optimized the removeAll function