Implemented cache clean and added tests