                     }
                     
                 } else if type == HKCategoryTypeIdentifierSleepAnalysis {
+                    dispatch_group_leave(group)//leave main group
                     //HealthManager.sharedManager.getStatisticsForSleepInPeriod(period)
                 } else {
                     HealthManager.sharedManager.getStatisticForPeriod(period, forType: type) { (statisticsVlues) in
-                        let statisticsVluesData = NSKeyedArchiver.archivedDataWithRootObject(statisticsVlues)
-                        Defaults[key] = statisticsVluesData
+                        let statisticsValuesData = NSKeyedArchiver.archivedDataWithRootObject(statisticsVlues)
+                        Defaults[key] = statisticsValuesData
                         dispatch_group_leave(group)//leave main group
                     }
                 }

                fatalError("*** An error occurred while calculating the statistics: \(error?.localizedDescription) ***")
            }
            var statisticsValues: [Double] = []
            statsCollection.enumerateStatisticsFromDate(startDate, toDate: endDate, withBlock: { (statistics, stop) in
                var doubleMaxValue = 0.0
                switch quantityType.aggregationStyle {
                    case .Discrete:
                        if let maxValue = statistics.averageQuantity() {
                            doubleMaxValue = maxValue.doubleValueForUnit(quantityType.defaultUnit!)

                        if let maxValue = statistics.sumQuantity() {
                            doubleMaxValue = maxValue.doubleValueForUnit(quantityType.defaultUnit!)
                        }
                    }
                    statisticsValues.append(round(doubleMaxValue))//add max double value
                })
                completion(statisticsVlues: statisticsValues)
            }
        }
        healthKitStore.executeQuery(statisticsQuery)
    }
    
    /**
        This method will collect statistics for types Heart Rate and Blood Preasure
    */
    public func getMinMaxValuesForPeriod(statisticsRange: HealthManagerStatisticsRangeType, forType type: String, completion: (statisticsMaxVlues: [Double], statisticsMinVlues: [Double]) -> Void) {
        
        let group = dispatch_group_create()
