         let feed1Ref = rootRef.child(path5)
         let feed2Ref = rootRef.child(path6)
         
-        followingRef.removeValue()
-        followerRef.removeValue()
-        followingCountRef.runTransactionBlock({ (data) -> FIRTransactionResult in
-            if let val = data.value as? Int , val > 0 {
-                data.value = val - 1
+        followingCountRef.runTransactionBlock({ (followingCountSnapshot) -> FIRTransactionResult in
+            if let val = followingCountSnapshot.value as? Int , val > 0 {
+                followingCountSnapshot.value = val - 1
+                
             } else {
-                data.value = 0
-            }
-            return FIRTransactionResult.success(withValue: data)
+                followingCountSnapshot.value = 0
+            }
+            return FIRTransactionResult.success(withValue: followingCountSnapshot)
             
             }, andCompletionBlock: { (err, committed, snap) in
                 guard committed else {
-                    error = .failedToUnfollow(message: "Failed to unfollow.")
+                    error = .failedToUnfollow(message: "Failed to unfollow")
                     callback?(error)
                     return
                 }
                 
-                followerCountRef.runTransactionBlock({ (data2) -> FIRTransactionResult in
-                    if let val = data2.value as? Int , val > 0 {
-                        data2.value = val - 1
+                followerCountRef.runTransactionBlock({ (followerCountSnapshot) -> FIRTransactionResult in
+                    if let val = followerCountSnapshot.value as? Int , val > 0 {
+                        followerCountSnapshot.value = val - 1
+                        
                     } else {
-                        data2.value = 0
+                        followerCountSnapshot.value = 0
                     }
-                    return FIRTransactionResult.success(withValue: data2)
+                    return FIRTransactionResult.success(withValue: followerCountSnapshot)
                     
                     }, andCompletionBlock: { (err, committed, snap) in
                         guard committed else {
-                            error = .failedToUnfollow(message: "Failed to unfollow.")
+                            error = .failedToUnfollow(message: "Failed to unfollow")
                             callback?(error)
                             return
                         }
                         
-                        feed2Ref.observeSingleEvent(of: .value, with: { (data3) in
-                            for child in data3.children {
-                                feed1Ref.child((child as AnyObject).key).removeValue()
+                        feed2Ref.observeSingleEvent(of: .value, with: { (feed2Snapshot) in
+                            for child in feed2Snapshot.children {
+                                guard let childSnapshot = child as? FIRDataSnapshot else {
+                                    continue
+                                }
+                                
+                                let key = childSnapshot.key
+                                feed1Ref.child(key).removeValue()
                             }
+                            
+                            followingRef.removeValue()
+                            followerRef.removeValue()
+                            
                             callback?(nil)
                         })
                 })

            return
        }
        
        let user = session.user
        let path1 = "users/\(user.id)/profile/following_count"
        let path2 = "users/\(user.id)/following/\(id)"
        let path3 = "users/\(id)/followers/\(user.id)"
        let path4 = "users/\(id)/profile/followers_count"
        let path5 = "users/\(user.id)/feed"
        let path6 = "users/\(id)/feed"
        
        let rootRef = FIRDatabase.database().reference()
        let followingCountRef = rootRef.child(path1)

            return
        }
        
        let uid = session.user.id
        let path1 = "user-profile/\(uid)/following_count"
        let path2 = "user-following/\(uid)/following/\(id)"
        let path3 = "user-follower/\(id)/followers/\(uid)"
        let path4 = "user-profile/\(id)/follower_count"
        let path5 = "user-feed/\(uid)/posts"
        let path6 = "user-feed/\(id)/posts"
        
        let rootRef = FIRDatabase.database().reference()
        let followingCountRef = rootRef.child(path1)
