Simplified code, removed messages counting using cache