             self.navigationController?.pushViewController(nextVC, animated: true)
         }
             
-            // if this is NOT a navigational node, i.e. links to a GitHub file
+        // if this is NOT a navigational node, i.e. links to a GitHub file
         else {
-            let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
-            let detailVC = storyBoard.instantiateViewController(withIdentifier: "FirebaseDataViewController") as! FirebaseDataViewController
-            detailVC.prevRef = self.tableViewData[indexPath.row]
-            
-            var retrievedGithubLink = ""
-            
-            self.ref.observeSingleEvent(of: .value, with: { (snapshot) in
-                
-                let value = snapshot.value as? NSDictionary
-                retrievedGithubLink = value?[self.tableViewData[indexPath.row]] as? String ?? ""
-                detailVC.githubLink = retrievedGithubLink
-                
-                let requestURL: NSURL = NSURL(string: self.getRawLink(link: retrievedGithubLink))!
-                let urlRequest: NSMutableURLRequest = NSMutableURLRequest(url: requestURL as URL)
-                let session = URLSession.shared
-                let task = session.dataTask(with: urlRequest as URLRequest) {
-                    (data, response, error) -> Void in
+            getGithubInfo(indexPath: indexPath)
+        }
+    }
+    
+    
+    /**
+     
+     Reads the PhoneInfo.json file and parses it to update UI elements in the FirebaseDataVC.
+     
+    **/
+    func getGithubInfo(indexPath: IndexPath) {
+        // get storyboard and instantiate next VC
+        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
+        let detailVC = storyBoard.instantiateViewController(withIdentifier: "FirebaseDataViewController") as! FirebaseDataViewController
+        detailVC.prevRef = self.tableViewData[indexPath.row]
+        
+        // Github link for trimming
+        var retrievedGithubLink = value?[self.tableViewData[indexPath.row]] as String
+        detailVC.githubLink = retrievedGithubLink
+        
+        // access the data from Firebase
+        self.ref.observeSingleEvent(of: .value, with: { (snapshot) in
+            
+            // initiate dictionary for storing JSON
+            let value = snapshot.value as? NSDictionary
+            
+            // initiate URL request to access JSON
+            let requestURL: NSURL = NSURL(string: self.getPhoneInfoJsonLink(link: retrievedGithubLink))!
+            let urlRequest: NSMutableURLRequest = NSMutableURLRequest(url: requestURL as URL)
+            let session = URLSession.shared
+            
+            // initiate asynchronous task to update UI accordingly
+            let task = session.dataTask(with: urlRequest as URLRequest) {
+                (data, response, error) -> Void in
+                
+                let httpResponse = response as! HTTPURLResponse
+                let statusCode = httpResponse.statusCode
+                
+                if (statusCode == 200) {
                     
-                    let httpResponse = response as! HTTPURLResponse
-                    let statusCode = httpResponse.statusCode
-                    
-                    if (statusCode == 200) {
+                    do{
                         
-                        do{
-                            
-                            let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! [String: Any]
-                            
-                            if let fetchedTitle = json["Title"] as? String {
-                                detailVC.titleData = fetchedTitle
-                                print(fetchedTitle)
-                            }
-                            if let fetchedDescription = json["Description"] as? String {
-                                detailVC.descriptionData = fetchedDescription
-                                print(fetchedDescription)
-                            }
-                            if let fetchedAuthor = json["Author"] as? String {
-                                detailVC.authorData = fetchedAuthor
-                                print(fetchedAuthor)
-                            }
-                            if let fetchedRemote = json["Remote Type"] as? String {
-                                detailVC.remoteTypeData = fetchedRemote
-                                print(fetchedRemote)
-                            }
-                        }catch {
-                            print("Error with Json: \(error)")
-                        }
+                        // parse and restore the JSON
+                        let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! [String: Any]
                         
+                        // store each respective UI element in the DetailVC
+                        
+                        if let fetchedTitle = json["Title"] as? String {
+                            detailVC.titleData = fetchedTitle
+                            print(fetchedTitle)
+                        }
+                        if let fetchedDescription = json["Description"] as? String {
+                            detailVC.descriptionData = fetchedDescription
+                            print(fetchedDescription)
+                        }
+                        if let fetchedAuthor = json["Author"] as? String {
+                            detailVC.authorData = fetchedAuthor
+                            print(fetchedAuthor)
+                        }
+                        if let fetchedRemote = json["Remote Type"] as? String {
+                            detailVC.remoteTypeData = fetchedRemote
+                            print(fetchedRemote)
+                        }
+                    } catch {
+                        print("Error with Json: \(error)")
                     }
-                    
                 }
-                
-                task.resume()
-                usleep(25000)
-                self.navigationController?.show(detailVC, sender: self)
-                
-            }) { (error) in
-                print(error.localizedDescription)
             }
             
-        }
-        
-        
-        
-        
-        
-    }
-    
+            // execute async task
+            task.resume()
+            
+            // TEMPORARY FIX. Fixed delay to allow time for the asynchronous task to complete.
+            usleep(30000)
+            
+            // present the detailVC
+            self.navigationController?.show(detailVC, sender: self)
+            
+        }) { (error) in
+            print(error.localizedDescription)
+        }
+    }
+
+
     // called to get the node's data from firebase
     func getFirebaseDatabase() {
         

//  FirebaseNavigationVIewController.swift
//  HomeRemote
//
//  Created by Lucas McDonald on 2/25/17.
//

import Foundation
import UIKit
import Firebase

class FirebaseNavigationViewController: UITableViewController {
    
    let cellReuseIdentifier = "cell"
    var tableViewData = [String]()
    var ref = FIRDatabase.database().reference().child("devices")
    var prevRef = ""
    var nodeDepth = 0
    
    @IBOutlet var tableViewList: UITableView!
    
    override func viewDidLoad() {
        
        // load table view stuff
        
        
        // Register the table view cell class and its reuse id
        self.tableViewList.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier)

        
    }
    
    /**
    
     Gets the link to the PhoneInfo.json file from the GitHub link.
 
    **/
    func getPhoneInfoJsonLink(link: String) -> String {
        if let rangeOfCom = link.range(of: "com", options: .backwards) {
            var trimmedLink = String(link.characters.suffix(from: rangeOfCom.upperBound))
            trimmedLink = "https://raw.githubusercontent.com" + trimmedLink + "/master/PhoneInfo.json"
            return trimmedLink
        }
        else{
