     }
     
     func deselectAllRows(){
-        for selectedIndexPath in self.tableView.indexPathsForSelectedRows! {  // as we only operate with one section
+        if(self.tableView.indexPathsForSelectedRows == nil){
+            return
+        }
+        
+        for selectedIndexPath in self.tableView.indexPathsForSelectedRows! {
             self.tableView.cellForRowAtIndexPath(selectedIndexPath)?.selectionStyle = UITableViewCellSelectionStyle.Default
             self.tableView.deselectRowAtIndexPath(selectedIndexPath, animated: false)
+        }
+    }
+    
+    func getIndexPathsForSelectedCells() -> [NSIndexPath] {
+        if(self.tableView.indexPathsForSelectedRows == nil){
+            return []
+        }
+        
+        // for some peculiar reason, simply using the index paths retrieved by "(..).indexPathsForSelectedRows" returns an additional index path
+        var indexPaths = self.tableView.indexPathsForSelectedRows!
+        indexPaths.removeLast()
+        return indexPaths
+    }
+    
+    func selectCellsFor(indexPaths: [NSIndexPath]) {
+        for indexPathForSelectedRow in indexPaths {
+            self.tableView.selectRowAtIndexPath(indexPathForSelectedRow, animated: false, scrollPosition: UITableViewScrollPosition.None)
         }
     }
     

        let scrollOffset = scrollView.contentOffset.y;
        
        if(self.numberOfReceiptsChangedUponLastUpdate &&
                !self.refreshControl.refreshing &&
                scrollOffset + scrollViewHeight >= 0.8 * scrollViewContentSizeHeight) {
            print("Debug: scrollViewDidScroll update") // <- DEBUG
            loadAdditionalReceipts()
        }
    }
    
    func loadAdditionalReceipts() {
        let previousNumberOfReceipts = self.receiptsTableViewDataSource.receipts.count
        self.fetchReceiptsFromAPI()  // this needs to be refactored to get(skip: receipts.count, take: default)
        let updatedNumberOfReceipts = self.receiptsTableViewDataSource.receipts.count
        
        self.numberOfReceiptsChangedUponLastUpdate = (previousNumberOfReceipts == updatedNumberOfReceipts) ? false : true;
    }
    
    func setupTableViewStyling() {

    
    func pullToRefresh() {
        print("Pull to refresh")
        self.deselectAllRows()
        self.receiptsTableViewDataSource.receipts.removeAll()
        self.tableView.reloadData()
        fetchReceiptsFromAPI()
        self.numberOfReceiptsChangedUponLastUpdate = true
    }
    
    func fetchReceiptsFromAPI() {
        if(!self.currentlyFetchingReceiptsData) {
            print("Attempting to fetch data...")
            self.currentlyFetchingReceiptsData = true
            
            // Completion method run upon GET-success
            // Note that this functions as a callback after receipts have been retrieved through the API.
            func setFetchedObjects(APICallResult: Dictionary<String,AnyObject>){
                let previouslySelectedIndexPaths: [NSIndexPath] = self.getIndexPathsForSelectedCells()
                
                let fetchedReceipts: [POSReceipt] = parseReceiptsFrom(APICallResult["receipt"]!)
                self.receiptsTableViewDataSource.receipts += fetchedReceipts
                
                self.numberOfReceiptsChangedUponLastUpdate = (fetchedReceipts.count > 0)
                
                self.tableView.reloadData()
                self.refreshControl.endRefreshing()
                
                self.selectCellsFor(previouslySelectedIndexPaths)
                self.updateNavbar()
                self.updateToolbarButtonItems()
                self.currentlyFetchingReceiptsData = false
            }
            func f(e: APIError){ print(e.altertMessage) }
            
            APIClient.sharedClient.updateReceiptsInMailboxWithParameters(skip: self.receiptsTableViewDataSource.receipts.count, take: 1,
                                                                              digipostAddress: self.mailboxDigipostAddress, uri: self.receiptsUri,
                                                                              success: setFetchedObjects, failure: f)
        }
    }
    
    func parseReceiptsFrom(APICallReceiptResult: AnyObject) -> Array<POSReceipt>{
        if(APICallReceiptResult.count == 0) {
            return []
        }
        
        var receiptList:Array<POSReceipt> = []
        
        let managedObjectContext = POSModelManager.sharedManager().managedObjectContext

        for index in 0..<APICallReceiptResult.count /* 0-indexed */ {
            var receiptAttributes: Dictionary<String, AnyObject> = Dictionary<String,AnyObject>()
            
            for receiptFieldKey in APICallReceiptResult[index].allKeys {
