     previousActivePane = atom.workspace.getActivePane()
     return unless editor?
     
-    editorPath = editor.getPath()
-    [isAlloy, alloyType, filename, fileExt] = editorPath.match(alloyRegExp) || []
-    isAppTss = /app\/styles\/app.tss$/.test editorPath;
-    isAlloyJs = /app\/alloy.js$/.test editorPath;
+    # if number of panes is under 3, make more.
+    numberOfPanes = atom.workspace.getPanes().length;
     
-    relatedFilePaths = []
-    if isAppTss
-      relatedFilePaths = [editorPath.replace('app/styles/app.tss','app/alloy.js')]
-    else if isAlloyJs
-      relatedFilePaths = [editorPath.replace('app/alloy.js','app/styles/app.tss')]
-    else if isAlloy
-      _.each alloyDirectoryMap, (folderName,ext)-> 
-        if ext!= fileExt
-          relatedFilePaths.push(getTargetPath(ext,editor.getPath()));
-    else
-      return
+    while atom.workspace.getPanes().length<3
+      lastPane = _.last(atom.workspace.getPanes())
+      if atom.config.get('titanium-alloy.numberOfSplitPane')==2 and atom.workspace.getActivePane().length == 2
+        lastPane.splitDown()
+      else
+        lastPane.splitRight()
+    
+    relatedFilePaths = getRelatedFilePath(editor.getPath())
+    return unless relatedFilePaths.length
       
+    panes = atom.workspace.getPanes()
     
-    if related2ndPane?.isAlive() != true
-      related2ndPane = atom.workspace.getActivePane().splitRight()
-    related2ndPane.activate();
-    atom.workspace.open(relatedFilePaths[0])
+    newPaneIdx = 0
+    for pane in panes
+      if pane != previousActivePane and relatedFilePaths[newPaneIdx]
+        pane.activate();
+        atom.workspace.open(relatedFilePaths[newPaneIdx++], {}).then( ->
+          previousActivePane.activate();
+        )
+          
+  closeAllRelatedPanes: () ->
+    editor = atom.workspace.getActiveTextEditor()
+    relatedFilePaths = getRelatedFilePath(editor.getPath())
+    allEditors = atom.workspace.getTextEditors()
     
-    if relatedFilePaths[1]
-      if related3rdPane?.isAlive() != true
-        if atom.config.get('titanium-alloy.numberOfSplitPane')==2
-          related3rdPane = related2ndPane.splitDown()
-        else
-          related3rdPane = related2ndPane.splitRight()
-      related3rdPane.activate();
-      atom.workspace.open(relatedFilePaths[1]).then( -> 
-        previousActivePane.activate();     # restore cursor focus
-      )
-  
-  closeAllRelatedPanes: () ->
-    # if related2ndPane?.isAlive() == true
-    related2ndPane.destroy() if related2ndPane?.isAlive()
-      
-    # if related3rdPane?.isAlive() == true
-    related3rdPane.destroy() if related3rdPane?.isAlive()
+    # find and close
+    for editor in allEditors
+      for path in relatedFilePaths
+        if path == editor.getPath()
+          editor.destroy()
       
   getTargetPath: getTargetPath
+  getRelatedFilePath : getRelatedFilePath

    atom.commands.add 'atom-workspace', 'titanium:openController': => @openFile('js')
    atom.commands.add 'atom-workspace', 'titanium:openAllRelatedFiles': => @openAllFiles()
    atom.commands.add 'atom-workspace', 'titanium:closeAllRelatedPanes': => @closeAllRelatedPanes()

  openFile: (type, options = {})->
    options.searchAllPanes = true
    atom.workspace.open getTargetPath(type), options

  currentFilePath.replace alloyRegExp, (match, p1, p2, p3, offset, string)->
    return "/#{alloyDirectoryMap[type]}/#{p2}.#{type}"

getRelatedFilePath = (editorPath) ->
  [isAlloy, alloyType, filename, fileExt] = editorPath.match(alloyRegExp) || []
  isAppTss = /app\/styles\/app.tss$/.test editorPath; # TODO : make more advanced Detection
  isAlloyJs = /app\/alloy.js$/.test editorPath; # TODO : make more advanced Detection
  
  relatedFilePaths = []
  
  if isAppTss
    relatedFilePaths = [editorPath.replace('app/styles/app.tss','app/alloy.js')]
  else if isAlloyJs
    relatedFilePaths = [editorPath.replace('app/alloy.js','app/styles/app.tss')]
  else if isAlloy
    _.each alloyDirectoryMap, (folderName,ext)-> 
      if ext!= fileExt
        relatedFilePaths.push(getTargetPath(ext,editorPath));

  relatedFilePaths
        
module.exports =
  activate: ->
    atom.commands.add 'atom-workspace', 'titanium:openView': => @openFile('xml')
