 class TrackTableViewController: UITableViewController {
     let tableCellReuseIdentifier = "trackTableViewCell"
     let cellHeight: CGFloat      = 80
-    
-    var playlist: Playlist! = nil
+
+    var playlist: Playlist!
     var playlistLoader: PlaylistLoader!
     var appDelegate: AppDelegate { get { return UIApplication.sharedApplication().delegate as! AppDelegate }}
+
+    var tracks: [Track] {
+        return playlist.getTracks()
+    }
+
     var isSelectedPlaylist: Bool {
-        get {
-            if playlist != nil && appDelegate.selectedPlaylist != nil {
-                return playlist!.id == appDelegate.selectedPlaylist!.id
-            }
+        if appDelegate.selectedPlaylist != nil {
+            return playlist.id == appDelegate.selectedPlaylist!.id
+        } else {
             return false
         }
     }
     var isPlayingPlaying: Bool {
-        get {
-            if playlist != nil && appDelegate.selectedPlaylist != nil {
-                return playlist!.id == appDelegate.selectedPlaylist!.id
-            }
+        if appDelegate.selectedPlaylist != nil {
+            return playlist.id == appDelegate.selectedPlaylist!.id
+        } else {
             return false
         }
     }

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if let _playlist = playlist {
            return _playlist.tracks.count
        }
        return 0
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return self.cellHeight
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(self.tableCellReuseIdentifier, forIndexPath: indexPath) as! TrackTableViewCell
        if let p = playlist {
            let track = p.getTracks()[indexPath.item]
            switch track.status {
            case .Loading:
                cell.trackNameLabel.text = "Loading...".localize()
            case .Unavailable:
                cell.trackNameLabel.text = "Unavailable".localize()
            default:
                if let title = track.title {
                    cell.trackNameLabel.text = title
                } else {
                    cell.trackNameLabel.text = ""
                }
            }
            let minutes = Int(floor(track.duration / 60))
            let seconds = Int(round(track.duration - Double(minutes) * 60))
            cell.durationLabel.text = String(format: "%.2d:%.2d", minutes, seconds)
            if let thumbnailUrl = track.thumbnailUrl {
                cell.thumbImgView.sd_setImageWithURL(thumbnailUrl)
            } else {
                cell.thumbImgView.image = UIImage(named: "default_thumb")
            }
            return cell
        } else {
            cell.trackNameLabel.text = ""
            cell.durationLabel.text  = ""
            cell.thumbImgView.image = UIImage(named: "default_thumb")
            return cell
        }
    }

    override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
        let remove = UITableViewRowAction(style: .Default, title: "Remove".localize()) {
            (action, indexPath) in
            Logger.sendUIActionEvent(self, action: "removeTrack", label: "\(indexPath.item)")
            self.playlist?.removeTrackAtIndex(UInt(indexPath.item))
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        }


                    if let __self = _self {
                        __self.tableView?.reloadRowsAtIndexPaths([NSIndexPath(forItem: index, inSection: 0)],
                            withRowAnimation: UITableViewRowAnimation.None)
                        Playlist.notifyChange(.Updated(__self.playlist))
                    }
                }
                return
