Modified after debugging and added a function to clear cache