Reorganized code and added method to check freshness