diff --git a/uk/ac/sanger/artemis/components/alignment/JamView.java b/uk/ac/sanger/artemis/components/alignment/JamView.java
index b196ba9a543d4f3ed34b6fda896dd143a0c6046f..db4ed9d497ba4d57f7581c865805e1ef34275ee5 100644
--- a/uk/ac/sanger/artemis/components/alignment/JamView.java
+++ b/uk/ac/sanger/artemis/components/alignment/JamView.java
@@ -1,4 +1,26 @@
-
+/* JamView
+ *
+ * created: 2009
+ *
+ * This file is part of Artemis
+ *
+ * Copyright(C) 2009  Genome Research Limited
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or(at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
 package uk.ac.sanger.artemis.components.alignment;
 
 import java.awt.BasicStroke;
@@ -61,7 +83,7 @@ public class JamView extends JPanel
   private Hashtable<String, Integer> seqLengths = new Hashtable<String, Integer>();
   private Vector<String> seqNames = new Vector<String>();
   private String bam;
-  private String sam;
+
   private EntryGroup entryGroup;
   private JScrollPane jspView;
   private JComboBox combo;
@@ -121,10 +143,13 @@ public class JamView extends JPanel
    */
   private void readHeader()
   {
-	String cmd[] = { "/Users/tjc/BAM/samtools-0.1.5c/samtools",  
+    String samtoolCmd = "";
+    if(System.getProperty("samtoolDir") != null)
+      samtoolCmd = System.getProperty("samtoolDir");
+    String cmd[] = { samtoolCmd+File.separator+"samtools",  
 			     "view", "-H", bam };
 	
-    RunSamTools samtools = new RunSamTools(cmd, null, null);
+    RunSamTools samtools = new RunSamTools(cmd, null, null, null);
 	
     if(samtools.getProcessStderr() != null)
       System.out.println(samtools.getProcessStderr());
@@ -181,42 +206,17 @@ public class JamView extends JPanel
 	for(int i=0; i<cmd.length;i++)
 	  System.out.print(cmd[i]+" ");
 	System.out.println();
-	RunSamTools samtools = new RunSamTools(cmd, null, null);
+	
+    if(readsInView == null)
+      readsInView = new Vector<Read>();
+    else
+      readsInView.clear();
+	RunSamTools samtools = new RunSamTools(cmd, null, null, readsInView);
 		
 	if(samtools.getProcessStderr() != null)
       System.out.println(samtools.getProcessStderr());
 	    
-	sam = samtools.getProcessStdout();
-
-	StringReader samReader = new StringReader(sam);
-	BufferedReader buff = new BufferedReader(samReader);
-	String line;
-	try 
-	{
-	  if(readsInView == null)
-	    readsInView = new Vector<Read>();
-	  else
-		readsInView.clear();
-	  while((line = buff.readLine()) != null)
-	  {
-		String fields[] = line.split("\t");
-
-		Read pread = new Read();
-		pread.qname = fields[0];
-		pread.flag  = Integer.parseInt(fields[1]);
-		pread.rname = fields[2];
-		pread.pos   = Integer.parseInt(fields[3]);
-		pread.mapq  = Short.parseShort(fields[4]);
-		pread.mpos  = Integer.parseInt(fields[7]);
-		pread.isize = Integer.parseInt(fields[8]);
-		pread.seq   = fields[9];
-		readsInView.add(pread);
-	  }
-	} 
-	catch (IOException e) 
-	{
-	  e.printStackTrace();
-	}
+	samtools.waitForStdout();
   }
   
   /**
@@ -465,6 +465,8 @@ public class JamView extends JPanel
     {
       public void itemStateChanged(ItemEvent e)
       {
+        laststart = -1;
+        lastend   = -1;
         setZoomLevel(JamView.this.nbasesInView);
       }
     });
@@ -492,7 +494,6 @@ public class JamView extends JPanel
     {
       public void mouseClicked(MouseEvent e)
       {
-        System.out.println("CLICK");
         JamView.this.requestFocus();
       }
     });
@@ -629,20 +630,6 @@ public class JamView extends JPanel
     return entry;
   }
   
-  class Read
-  {
-    String qname; // query name
-    int flag;     // bitwise flag
-    String rname; // reference name
-    int pos;      // leftmost coordinate
-    short mapq;   // MAPping Quality
-    String cigar; // extended CIGAR string
-    String mrnm;  // Mate Reference sequence NaMe; Ò=Ó if the same as rname
-    int mpos;     // leftmost Mate POSition
-    int isize;    // inferred Insert SIZE
-    String seq;   // query SEQuence; Ò=Ó for a match to the reference; n/N/. for ambiguity
-  }
-  
   class ReadComparator implements Comparator
   {
     public int compare(Object o1, Object o2) 
diff --git a/uk/ac/sanger/artemis/components/alignment/Read.java b/uk/ac/sanger/artemis/components/alignment/Read.java
new file mode 100644
index 0000000000000000000000000000000000000000..02d765664fa92c230f2dd8aba62a11526fde1d8d
--- /dev/null
+++ b/uk/ac/sanger/artemis/components/alignment/Read.java
@@ -0,0 +1,38 @@
+/* Read
+ *
+ * created: 2009
+ *
+ * This file is part of Artemis
+ *
+ * Copyright(C) 2009  Genome Research Limited
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or(at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+package uk.ac.sanger.artemis.components.alignment;
+
+class Read
+{
+  String qname; // query name
+  int flag;     // bitwise flag
+  String rname; // reference name
+  int pos;      // leftmost coordinate
+  short mapq;   // MAPping Quality
+  String cigar; // extended CIGAR string
+  String mrnm;  // Mate Reference sequence NaMe; Ò=Ó if the same as rname
+  int mpos;     // leftmost Mate POSition
+  int isize;    // inferred Insert SIZE
+  String seq;   // query SEQuence; Ò=Ó for a match to the reference; n/N/. for ambiguity
+}
\ No newline at end of file
diff --git a/uk/ac/sanger/artemis/components/alignment/RunSamTools.java b/uk/ac/sanger/artemis/components/alignment/RunSamTools.java
index 2ac1284d4116bb25aee4456eaa61a74cd737fdd3..47dda18fc8bd63722aed9db6a9c0e02da1fb7c41 100644
--- a/uk/ac/sanger/artemis/components/alignment/RunSamTools.java
+++ b/uk/ac/sanger/artemis/components/alignment/RunSamTools.java
@@ -1,8 +1,30 @@
-
+/* RunSamTools
+ *
+ * created: 2009
+ *
+ * This file is part of Artemis
+ *
+ * Copyright(C) 2009  Genome Research Limited
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or(at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
 package uk.ac.sanger.artemis.components.alignment;
 
 import java.io.*;
-import javax.swing.JTextArea;
+import java.util.List;
 
 /**
 * Used to run an samtools process this reads stdout and 
@@ -14,10 +36,10 @@ public class RunSamTools
   /** running process */
   private Process p;
   /** standard out */
-  private StringBuffer stdout = new StringBuffer();
+  private List<Read> readsInView;
   /** standard error */
   private StringBuffer stderr = new StringBuffer();
-  
+  private StringBuffer stdout = new StringBuffer();
   private String initialIOError = null;
   
   /** running directory */
@@ -26,8 +48,6 @@ public class RunSamTools
   private String status;
   private StdoutHandler stdouth;
   private StderrHandler stderrh;
-  private JTextArea textArea;
-
 
   /**
   * @param cmd              command to run
@@ -35,9 +55,12 @@ public class RunSamTools
   * @param project          running directory
   */
   public RunSamTools(String cmd[], 
-                     String[] envp, File project)
+                     String[] envp,
+                     File project,
+                     List<Read> readsInView)
   {
     //this.project = project;
+    this.readsInView = readsInView;
     status = "0";
 
     Runtime run = Runtime.getRuntime();
@@ -116,29 +139,36 @@ public class RunSamTools
   */
   private void readProcessStdout()
   {
-    BufferedInputStream stdoutStream = null;
+    InputStreamReader stdoutStream = null;
     BufferedReader stdoutRead = null;
     try
     {
       //String line;
       stdoutStream =
-         new BufferedInputStream(p.getInputStream());
+         new InputStreamReader(p.getInputStream());
       stdoutRead =
-         new BufferedReader(new InputStreamReader(stdoutStream));
-    
-      char c[] = new char[200];
-      int nc = 0;
-      String chunk;
-
-      while((nc = stdoutRead.read(c,0,200)) != -1)
+         new BufferedReader(stdoutStream);    
+      
+      String line;
+      while((line = stdoutRead.readLine()) != null)
       {
-        chunk  = new String(c,0,nc);
-        stdout = stdout.append(chunk);
-        if(textArea != null)
+        if(readsInView != null)
         {
-          textArea.append(chunk);
-          textArea.setCaretPosition(textArea.getDocument().getLength());
+          String fields[] = line.split("\t");
+
+          Read pread = new Read();
+          pread.qname = fields[0];
+          pread.flag  = Integer.parseInt(fields[1]);
+          pread.rname = fields[2];
+          pread.pos   = Integer.parseInt(fields[3]);
+          pread.mapq  = Short.parseShort(fields[4]);
+          pread.mpos  = Integer.parseInt(fields[7]);
+          pread.isize = Integer.parseInt(fields[8]);
+          pread.seq   = fields[9];
+          readsInView.add(pread);
         }
+        else
+          stdout.append(line+"\n");
       }
     }
     catch (IOException io)
@@ -172,59 +202,43 @@ public class RunSamTools
   }
 
   /**
-  * This method can be called after the process has completed
-  * to write the stdout to the project directory.
-  */
-//  private void writeStdout()
-//  {
-//    if(project != null)
-//    {
-//      PrintWriter out = null;
-//      String fname = "";
-//      try
-//      {
-//        fname = project.getCanonicalPath() + 
-//                             "/application_stdout";
-//        File so = new File(fname);
-//
-//        if(!so.exists())
-//          so.createNewFile();
-//
-//        out = new PrintWriter(new FileWriter(fname,true));
-//        out.println(stdout);
-//      }
-//      catch(IOException ioe)
-//      {
-//        System.err.println("RunEmbossApplication2: Error writing" +
-//                            fname);
-//      }
-//      finally
-//      {
-//        if(out!=null)
-//          out.close();
-//      }
-//    }
-//  }
-
-  /**
-  * @return standard out
-  */
-  public String getProcessStdout()
-  {
-    try
+   * @return standard out
+   */
+   public void waitForStdout()
+   {
+     try
+     {
+       // make sure we hang around for stdout
+       while(stdouth.isAlive())
+         Thread.sleep(10);
+     }
+     catch(InterruptedException ie)
+     {
+       ie.printStackTrace();
+     }
+                                                                                 
+     return;
+   }
+   
+   /**
+    * @return standard out
+    */
+    public String getProcessStdout()
     {
-      // make sure we hang around for stdout
-      while(stdouth.isAlive())
-        Thread.sleep(10);
-    }
-    catch(InterruptedException ie)
-    {
-      ie.printStackTrace();
+      try
+      {
+        // make sure we hang around for stdout
+        while(stdouth.isAlive())
+          Thread.sleep(10);
+      }
+      catch(InterruptedException ie)
+      {
+        ie.printStackTrace();
+      }
+                                                                                  
+      return stdout.toString();
     }
-                                                                                
-    return stdout.toString();
-  }
-
+   
   /**
   * @return stderr
   */