     public func preview(text: String!, onSuccess: ([String: AnyObject]) -> (), onError: (PreviewError) -> ()) {
         
         self.resetResult()
+        self.wasOnMainThread = NSThread.isMainThread()
         
         self.text = text
         

                
            } else {
                
                dispatch_async(dispatch_get_main_queue()) {
                    
                    completion(url)
                    
                }
                
            }
            
        }

                    // Try to get the page with its default enconding
                    var source = try String(contentsOfURL: sourceUrl!).extendedTrim
                    
                    if self.wasOnMainThread {
                        
                        dispatch_async(dispatch_get_main_queue()) {
                            
                            source = self.cleanSource(source)
                            
                            self.performPageCrawling(source)
                            
                            completion()
                        }
                    }
                    else {
                        source = self.cleanSource(source)
                        
                        self.performPageCrawling(source)
                        
                        completion()
                    }
                    
                } catch _ as NSError {
