merge with hadoop code
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerUtil.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/data/KmerUtil.java
similarity index 95%
rename from genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerUtil.java
rename to genomix/genomix-data/src/main/java/edu/uci/ics/genomix/data/KmerUtil.java
index 68dec30..5dc04e0 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerUtil.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/data/KmerUtil.java
@@ -13,7 +13,9 @@
  * limitations under the License.
  */
 
-package edu.uci.ics.genomix.type;
+package edu.uci.ics.genomix.data;
+
+import edu.uci.ics.genomix.type.GeneCode;
 
 public class KmerUtil {
     public static final String empty = "";
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/data/Marshal.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/data/Marshal.java
new file mode 100644
index 0000000..219def6
--- /dev/null
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/data/Marshal.java
@@ -0,0 +1,15 @@
+package edu.uci.ics.genomix.data;
+
+public class Marshal {
+    public static int getInt(byte[] bytes, int offset) {
+        return ((bytes[offset] & 0xff) << 24) + ((bytes[offset + 1] & 0xff) << 16) + ((bytes[offset + 2] & 0xff) << 8)
+                + ((bytes[offset + 3] & 0xff) << 0);
+    }
+    
+    public static void putInt(int val, byte[] bytes, int offset) {
+        bytes[offset] = (byte)((val >>> 24) & 0xFF);        
+        bytes[offset + 1] = (byte)((val >>> 16) & 0xFF);
+        bytes[offset + 2] = (byte)((val >>>  8) & 0xFF);
+        bytes[offset + 3] = (byte)((val >>>  0) & 0xFF);
+    }
+}
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java
index 7e578f6..bbe4419 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java
@@ -24,6 +24,8 @@
 import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.io.WritableComparator;
 
+import edu.uci.ics.genomix.data.KmerUtil;
+
 /**
  * Variable kmer length byteswritable
  * It was used to generate the graph in which phase the kmer length doesn't change.
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/NodeWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/NodeWritable.java
index cbff5a6..6b3be5f 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/NodeWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/NodeWritable.java
@@ -1,20 +1,36 @@
 package edu.uci.ics.genomix.type;
 
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
 
-public class NodeWritable {
+import org.apache.hadoop.io.WritableComparable;
+
+public class NodeWritable implements WritableComparable<NodeWritable> {
     private PositionWritable nodeID;
     private int countOfKmer;
     private PositionListWritable incomingList;
     private PositionListWritable outgoingList;
-
-    public NodeWritable() {
+    private KmerBytesWritable kmer;
+    
+    @SuppressWarnings("deprecation")
+    public NodeWritable(){
         nodeID = new PositionWritable();
         countOfKmer = 0;
         incomingList = new PositionListWritable();
         outgoingList = new PositionListWritable();
+        kmer = new KmerBytesWritable();
     }
-    
-    public int getCount(){
+
+    public NodeWritable(int kmerSize) {
+        nodeID = new PositionWritable();
+        countOfKmer = 0;
+        incomingList = new PositionListWritable();
+        outgoingList = new PositionListWritable();
+        kmer = new KmerBytesWritable(kmerSize);
+    }
+
+    public int getCount() {
         return countOfKmer;
     }
 
@@ -57,11 +73,14 @@
         return nodeID;
     }
 
+    public KmerBytesWritable getKmer() {
+        return kmer;
+    }
+
     public void mergeNextWithinOneRead(NodeWritable nextNodeEntry) {
-        this.countOfKmer += nextNodeEntry.countOfKmer;
-        for(PositionWritable pos : nextNodeEntry.getOutgoingList()){
-            this.outgoingList.append(pos);
-        }
+        this.countOfKmer += 1;
+        this.outgoingList.set(nextNodeEntry.outgoingList);
+        kmer.mergeKmerWithNextCode(nextNodeEntry.kmer.getGeneCodeAtPosition(nextNodeEntry.kmer.getKmerLength() - 1));
     }
 
     public void set(NodeWritable node) {
@@ -69,6 +88,35 @@
         this.countOfKmer = node.countOfKmer;
         this.incomingList.set(node.getIncomingList());
         this.outgoingList.set(node.getOutgoingList());
+        this.kmer.set(node.kmer);
+    }
+
+    @Override
+    public void readFields(DataInput in) throws IOException {
+        this.nodeID.readFields(in);
+        this.countOfKmer = in.readInt();
+        this.incomingList.readFields(in);
+        this.outgoingList.readFields(in);
+        this.kmer.readFields(in);
+    }
+
+    @Override
+    public void write(DataOutput out) throws IOException {
+        this.nodeID.write(out);
+        out.writeInt(this.countOfKmer);
+        this.incomingList.write(out);
+        this.outgoingList.write(out);
+        this.kmer.write(out);
+    }
+
+    @Override
+    public int compareTo(NodeWritable other) {
+        return this.nodeID.compareTo(other.nodeID);
+    }
+
+    @Override
+    public int hashCode() {
+        return nodeID.hashCode();
     }
 
 }
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java
index e006210..af07ed5 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionListWritable.java
@@ -4,32 +4,35 @@
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Iterator;
+
 import org.apache.hadoop.io.Writable;
 
-public class PositionListWritable implements Writable, Iterable<PositionWritable> {
-    private byte[] storage;
-    private int offset;
-    private int valueCount;
-    private static final byte[] EMPTY = {};
+import edu.uci.ics.genomix.data.Marshal;
 
-    private PositionWritable posIter = new PositionWritable();
+public class PositionListWritable implements Writable, Iterable<PositionWritable> {
+    protected byte[] storage;
+    protected int offset;
+    protected int valueCount;
+    protected static final byte[] EMPTY = {};
+
+    protected PositionWritable posIter = new PositionWritable();
 
     public PositionListWritable() {
         this.storage = EMPTY;
         this.valueCount = 0;
         this.offset = 0;
     }
-    
-    public PositionListWritable(int count, byte [] data, int offset){
+
+    public PositionListWritable(int count, byte[] data, int offset) {
         setNewReference(count, data, offset);
     }
 
-    public void setNewReference(int count, byte[] data, int offset){
+    public void setNewReference(int count, byte[] data, int offset) {
         this.valueCount = count;
         this.storage = data;
         this.offset = offset;
     }
-    
+
     protected void setSize(int size) {
         if (size > getCapacity()) {
             setCapacity((size * 3 / 2));
@@ -44,26 +47,13 @@
         if (new_cap > getCapacity()) {
             byte[] new_data = new byte[new_cap];
             if (storage.length - offset > 0) {
-                System.arraycopy(storage, offset, new_data, 0, storage.length-offset);
+                System.arraycopy(storage, offset, new_data, 0, storage.length - offset);
             }
             storage = new_data;
             offset = 0;
         }
     }
 
-    @Override
-    public void readFields(DataInput in) throws IOException {
-        this.valueCount = in.readInt();
-        setSize(valueCount * PositionWritable.LENGTH);
-        in.readFully(storage, offset, valueCount * PositionWritable.LENGTH);
-    }
-
-    @Override
-    public void write(DataOutput out) throws IOException {
-        out.writeInt(valueCount);
-        out.write(storage, offset, valueCount * PositionWritable.LENGTH);
-    }
-
     public PositionWritable getPosition(int i) {
         if (i >= valueCount) {
             throw new ArrayIndexOutOfBoundsException("No such positions");
@@ -71,7 +61,7 @@
         posIter.setNewReference(storage, offset + i * PositionWritable.LENGTH);
         return posIter;
     }
-    
+
     @Override
     public Iterator<PositionWritable> iterator() {
         Iterator<PositionWritable> it = new Iterator<PositionWritable>() {
@@ -114,14 +104,14 @@
 
     public void append(PositionWritable pos) {
         setSize((1 + valueCount) * PositionWritable.LENGTH);
-        System.arraycopy(pos.getByteArray(), pos.getStartOffset(), storage, offset + valueCount * PositionWritable.LENGTH,
-                pos.getLength());
+        System.arraycopy(pos.getByteArray(), pos.getStartOffset(), storage, offset + valueCount
+                * PositionWritable.LENGTH, pos.getLength());
         valueCount += 1;
     }
 
     public void append(int readID, byte posInRead) {
         setSize((1 + valueCount) * PositionWritable.LENGTH);
-        putInt(readID, storage, offset + valueCount * PositionWritable.LENGTH);
+        Marshal.putInt(readID, storage, offset + valueCount * PositionWritable.LENGTH);
         storage[offset + valueCount * PositionWritable.LENGTH + PositionWritable.INTBYTES] = posInRead;
         valueCount += 1;
     }
@@ -139,19 +129,20 @@
     }
 
     public int getLength() {
-        return valueCount * PositionWritable.LENGTH ;
+        return valueCount * PositionWritable.LENGTH;
     }
-    
-    public static int getInt(byte[] bytes, int offset) {
-        return ((bytes[offset] & 0xff) << 24) + ((bytes[offset + 1] & 0xff) << 16) + ((bytes[offset + 2] & 0xff) << 8)
-                + ((bytes[offset + 3] & 0xff) << 0);
+
+    @Override
+    public void readFields(DataInput in) throws IOException {
+        this.valueCount = in.readInt();
+        setSize(valueCount * PositionWritable.LENGTH);
+        in.readFully(storage, offset, valueCount * PositionWritable.LENGTH);
     }
-    
-    public static void putInt(int val, byte[] bytes, int offset) {
-        bytes[offset] = (byte)((val >>> 24) & 0xFF);        
-        bytes[offset + 1] = (byte)((val >>> 16) & 0xFF);
-        bytes[offset + 2] = (byte)((val >>>  8) & 0xFF);
-        bytes[offset + 3] = (byte)((val >>>  0) & 0xFF);
+
+    @Override
+    public void write(DataOutput out) throws IOException {
+        out.writeInt(valueCount);
+        out.write(storage, offset, valueCount * PositionWritable.LENGTH);
     }
 
 }
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java
index d8d85ec..c7f24ec 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/PositionWritable.java
@@ -3,11 +3,15 @@
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
-import org.apache.hadoop.io.Writable;
 
-public class PositionWritable implements Writable {
-    private byte[] storage;
-    private int offset;
+import org.apache.hadoop.io.WritableComparable;
+import org.apache.hadoop.io.WritableComparator;
+
+import edu.uci.ics.genomix.data.Marshal;
+
+public class PositionWritable implements WritableComparable<PositionWritable> {
+    protected byte[] storage;
+    protected int offset;
     public static final int LENGTH = 5;
     public static final int INTBYTES = 4;
 
@@ -31,12 +35,12 @@
     }
     
     public void set(int readID, byte posInRead) {
-        putInt(readID, storage, offset);
+        Marshal.putInt(readID, storage, offset);
         storage[offset + INTBYTES] = posInRead;
     }
 
     public int getReadID() {
-        return getInt(storage, offset);
+        return Marshal.getInt(storage, offset);
     }
 
     public byte getPosInRead() {
@@ -54,7 +58,7 @@
     public int getLength() {
         return LENGTH;
     }
-    
+
     @Override
     public void readFields(DataInput in) throws IOException {
         in.readFully(storage, offset, LENGTH);
@@ -65,16 +69,51 @@
         out.write(storage, offset, LENGTH);
     }
     
-    public static int getInt(byte[] bytes, int offset) {
-        return ((bytes[offset] & 0xff) << 24) + ((bytes[offset + 1] & 0xff) << 16) + ((bytes[offset + 2] & 0xff) << 8)
-                + ((bytes[offset + 3] & 0xff) << 0);
-    }
-    
-    public static void putInt(int val, byte[] bytes, int offset) {
-        bytes[offset] = (byte)((val >>> 24) & 0xFF);        
-        bytes[offset + 1] = (byte)((val >>> 16) & 0xFF);
-        bytes[offset + 2] = (byte)((val >>>  8) & 0xFF);
-        bytes[offset + 3] = (byte)((val >>>  0) & 0xFF);
+    @Override
+    public int hashCode() {
+        return this.getReadID();
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (!(o instanceof PositionWritable))
+            return false;
+        PositionWritable other = (PositionWritable) o;
+        return this.getReadID() == other.getReadID() && this.getPosInRead() == other.getPosInRead();
+    }
+
+    @Override
+    public int compareTo(PositionWritable other) {
+        int diff = this.getReadID() - other.getReadID();
+        if (diff == 0) {
+            return this.getPosInRead() - other.getPosInRead();
+        }
+        return diff;
+    }
+
+    @Override
+    public String toString() {
+        return "(" + Integer.toString(getReadID()) + "," + Integer.toString((int) getPosInRead()) + ")";
+    }
+
+    /** A Comparator optimized for IntWritable. */
+    public static class Comparator extends WritableComparator {
+        public Comparator() {
+            super(PositionWritable.class);
+        }
+
+        public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
+            int thisValue = Marshal.getInt(b1, s1);
+            int thatValue = Marshal.getInt(b2, s2);
+            int diff = thisValue - thatValue;
+            if (diff == 0) {
+                return b1[s1 + INTBYTES] - b2[s2 + INTBYTES];
+            }
+            return diff;
+        }
+    }
+
+    static { // register this comparator
+        WritableComparator.define(PositionWritable.class, new Comparator());
+    }
 }
diff --git a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/NodeReference.java b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/NodeReference.java
index 4e99865..fcc61d5 100644
--- a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/NodeReference.java
+++ b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/NodeReference.java
@@ -1,114 +1,12 @@
 package edu.uci.ics.genomix.hyracks.data.primitive;
 
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
+import edu.uci.ics.genomix.type.NodeWritable;
 
-import org.apache.hadoop.io.WritableComparable;
-
-import edu.uci.ics.genomix.type.KmerBytesWritable;
-
-public class NodeReference implements WritableComparable<NodeReference> {
-    private PositionReference nodeID;
-    private int countOfKmer;
-    private PositionListReference incomingList;
-    private PositionListReference outgoingList;
-    private KmerBytesWritable kmer;
+public class NodeReference extends NodeWritable{
 
     public NodeReference(int kmerSize) {
-        nodeID = new PositionReference();
-        countOfKmer = 0;
-        incomingList = new PositionListReference();
-        outgoingList = new PositionListReference();
-        kmer = new KmerBytesWritable(kmerSize);
+        super(kmerSize);
+        // TODO Auto-generated constructor stub
     }
-
-    public int getCount() {
-        return countOfKmer;
-    }
-
-    public void setCount(int count) {
-        this.countOfKmer = count;
-    }
-
-    public void setNodeID(PositionReference ref) {
-        this.setNodeID(ref.getReadID(), ref.getPosInRead());
-    }
-
-    public void setNodeID(int readID, byte posInRead) {
-        nodeID.set(readID, posInRead);
-    }
-
-    public void setIncomingList(PositionListReference incoming) {
-        incomingList.set(incoming);
-    }
-
-    public void setOutgoingList(PositionListReference outgoing) {
-        outgoingList.set(outgoing);
-    }
-
-    public void reset() {
-        nodeID.set(0, (byte) 0);
-        incomingList.reset();
-        outgoingList.reset();
-        countOfKmer = 0;
-    }
-
-    public PositionListReference getIncomingList() {
-        return incomingList;
-    }
-
-    public PositionListReference getOutgoingList() {
-        return outgoingList;
-    }
-
-    public PositionReference getNodeID() {
-        return nodeID;
-    }
-
-    public KmerBytesWritable getKmer() {
-        return kmer;
-    }
-
-    public void mergeNextWithinOneRead(NodeReference nextNodeEntry) {
-        this.countOfKmer += 1;
-        this.outgoingList.set(nextNodeEntry.outgoingList);
-        kmer.mergeKmerWithNextCode(nextNodeEntry.kmer.getGeneCodeAtPosition(nextNodeEntry.kmer.getKmerLength() - 1));
-    }
-
-    public void set(NodeReference node) {
-        this.nodeID.set(node.getNodeID().getReadID(), node.getNodeID().getPosInRead());
-        this.countOfKmer = node.countOfKmer;
-        this.incomingList.set(node.getIncomingList());
-        this.outgoingList.set(node.getOutgoingList());
-        this.kmer.set(node.kmer);
-    }
-
-    @Override
-    public void readFields(DataInput in) throws IOException {
-        this.nodeID.readFields(in);
-        this.countOfKmer = in.readInt();
-        this.incomingList.readFields(in);
-        this.outgoingList.readFields(in);
-        this.kmer.readFields(in);
-    }
-
-    @Override
-    public void write(DataOutput out) throws IOException {
-        this.nodeID.write(out);
-        out.writeInt(this.countOfKmer);
-        this.incomingList.write(out);
-        this.outgoingList.write(out);
-        this.kmer.write(out);
-    }
-
-    @Override
-    public int compareTo(NodeReference other) {
-        return this.nodeID.compareTo(other.nodeID);
-    }
-
-    @Override
-    public int hashCode() {
-        return nodeID.hashCode();
-    }
+ 
 }
diff --git a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionListReference.java b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionListReference.java
index d4c8f7b..7b46fa5 100644
--- a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionListReference.java
+++ b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionListReference.java
@@ -1,152 +1,7 @@
 package edu.uci.ics.genomix.hyracks.data.primitive;
 
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Iterator;
-
-import org.apache.hadoop.io.Writable;
-
+import edu.uci.ics.genomix.type.PositionListWritable;
 import edu.uci.ics.hyracks.data.std.api.IValueReference;
-import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
 
-public class PositionListReference implements Writable, Iterable<PositionReference>, IValueReference {
-    private byte[] storage;
-    private int offset;
-    private int valueCount;
-    private static final byte[] EMPTY = {};
-
-    private PositionReference posIter = new PositionReference();
-
-    public PositionListReference() {
-        this.storage = EMPTY;
-        this.valueCount = 0;
-        this.offset = 0;
-    }
-
-    public PositionListReference(int count, byte[] data, int offset) {
-        setNewReference(count, data, offset);
-    }
-
-    protected void setSize(int size) {
-        if (size > getCapacity()) {
-            setCapacity((size * 3 / 2));
-        }
-    }
-
-    protected int getCapacity() {
-        return storage.length - offset;
-    }
-
-    protected void setCapacity(int new_cap) {
-        if (new_cap > getCapacity()) {
-            byte[] new_data = new byte[new_cap];
-            if (storage.length - offset > 0) {
-                System.arraycopy(storage, offset, new_data, 0, storage.length - offset);
-            }
-            storage = new_data;
-            offset = 0;
-        }
-    }
-
-    public PositionReference getPosition(int i) {
-        if (i >= valueCount) {
-            throw new ArrayIndexOutOfBoundsException("No such positions");
-        }
-        posIter.setNewReference(storage, offset + i * PositionReference.LENGTH);
-        return posIter;
-    }
-
-    @Override
-    public Iterator<PositionReference> iterator() {
-        Iterator<PositionReference> it = new Iterator<PositionReference>() {
-
-            private int currentIndex = 0;
-
-            @Override
-            public boolean hasNext() {
-                return currentIndex < valueCount;
-            }
-
-            @Override
-            public PositionReference next() {
-                return getPosition(currentIndex);
-            }
-
-            @Override
-            public void remove() {
-                // TODO Auto-generated method stub
-            }
-        };
-        return it;
-    }
-
-    public void setNewReference(int count, byte[] data, int offset) {
-        this.valueCount = count;
-        this.storage = data;
-        this.offset = offset;
-    }
-
-    public void set(PositionListReference list2) {
-        set(list2.valueCount, list2.storage, list2.offset);
-    }
-
-    public void set(int valueCount, byte[] newData, int offset) {
-        this.valueCount = valueCount;
-        setSize(valueCount * PositionReference.LENGTH);
-        if (valueCount > 0) {
-            System.arraycopy(newData, offset, storage, this.offset, valueCount * PositionReference.LENGTH);
-        }
-    }
-
-    public void reset() {
-        valueCount = 0;
-    }
-
-    public void append(PositionReference pos) {
-        setSize((1 + valueCount) * PositionReference.LENGTH);
-        System.arraycopy(pos.getByteArray(), pos.getStartOffset(), storage, offset + valueCount
-                * PositionReference.LENGTH, pos.getLength());
-        valueCount += 1;
-    }
-
-    public void append(int readID, byte posInRead) {
-        setSize((1 + valueCount) * PositionReference.LENGTH);
-        IntegerSerializerDeserializer.putInt(readID, storage, offset + valueCount * PositionReference.LENGTH);
-        storage[offset + valueCount * PositionReference.LENGTH + PositionReference.INTBYTES] = posInRead;
-        valueCount += 1;
-    }
-
-    public int getCountOfPosition() {
-        return valueCount;
-    }
-
-    @Override
-    public byte[] getByteArray() {
-        return storage;
-    }
-
-    @Override
-    public int getStartOffset() {
-        return offset;
-    }
-
-    @Override
-    public int getLength() {
-        return valueCount * PositionReference.LENGTH;
-    }
-
-    @Override
-    public void readFields(DataInput in) throws IOException {
-        this.valueCount = in.readInt();
-        setSize(valueCount * PositionReference.LENGTH);
-        in.readFully(storage, offset, valueCount * PositionReference.LENGTH);
-    }
-
-    @Override
-    public void write(DataOutput out) throws IOException {
-        out.writeInt(valueCount);
-        out.write(storage, offset, valueCount * PositionReference.LENGTH);
-    }
-
+public class PositionListReference extends PositionListWritable implements  IValueReference {
 }
diff --git a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionReference.java b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionReference.java
index 29e894b..4c19595 100644
--- a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionReference.java
+++ b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/data/primitive/PositionReference.java
@@ -1,123 +1,7 @@
 package edu.uci.ics.genomix.hyracks.data.primitive;
 
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.hadoop.io.WritableComparable;
-import org.apache.hadoop.io.WritableComparator;
-
+import edu.uci.ics.genomix.type.PositionWritable;
 import edu.uci.ics.hyracks.data.std.api.IValueReference;
-import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
 
-public class PositionReference implements IValueReference, WritableComparable<PositionReference> {
-    private byte[] storage;
-    private int offset;
-    public static final int LENGTH = 5;
-    public static final int INTBYTES = 4;
-
-    public PositionReference() {
-        storage = new byte[LENGTH];
-        offset = 0;
-    }
-
-    public PositionReference(byte[] storage, int offset) {
-        setNewReference(storage, offset);
-    }
-
-    public PositionReference(int readID, byte posInRead) {
-        this();
-        set(readID, posInRead);
-    }
-
-    public void set(int readID, byte posInRead) {
-        IntegerSerializerDeserializer.putInt(readID, storage, offset);
-        storage[offset + INTBYTES] = posInRead;
-    }
-
-    public void setNewReference(byte[] storage, int offset) {
-        this.storage = storage;
-        this.offset = offset;
-    }
-
-    public int getReadID() {
-        return IntegerSerializerDeserializer.getInt(storage, offset);
-    }
-
-    public byte getPosInRead() {
-        return storage[offset + INTBYTES];
-    }
-
-    @Override
-    public byte[] getByteArray() {
-        return storage;
-    }
-
-    @Override
-    public int getStartOffset() {
-        return offset;
-    }
-
-    @Override
-    public int getLength() {
-        return LENGTH;
-    }
-
-    @Override
-    public void readFields(DataInput in) throws IOException {
-        in.readFully(storage, offset, LENGTH);
-    }
-
-    @Override
-    public void write(DataOutput out) throws IOException {
-        out.write(storage, offset, LENGTH);
-    }
-
-    @Override
-    public int hashCode() {
-        return this.getReadID();
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (!(o instanceof PositionReference))
-            return false;
-        PositionReference other = (PositionReference) o;
-        return this.getReadID() == other.getReadID() && this.getPosInRead() == other.getPosInRead();
-    }
-
-    @Override
-    public int compareTo(PositionReference other) {
-        int diff = this.getReadID() - other.getReadID();
-        if (diff == 0) {
-            return this.getPosInRead() - other.getPosInRead();
-        }
-        return diff;
-    }
-
-    @Override
-    public String toString() {
-        return "(" + Integer.toString(getReadID()) + "," + Integer.toString((int) getPosInRead()) + ")";
-    }
-
-    /** A Comparator optimized for IntWritable. */
-    public static class Comparator extends WritableComparator {
-        public Comparator() {
-            super(PositionReference.class);
-        }
-
-        public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
-            int thisValue = IntegerSerializerDeserializer.getInt(b1, s1);
-            int thatValue = IntegerSerializerDeserializer.getInt(b2, s2);
-            int diff = thisValue - thatValue;
-            if (diff == 0){
-                return b1[s1+INTBYTES] - b2[s2+INTBYTES];
-            }
-            return diff;
-        }
-    }
-
-    static { // register this comparator
-        WritableComparator.define(PositionReference.class, new Comparator());
-    }
+public class PositionReference extends PositionWritable implements IValueReference {
 }
diff --git a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/dataflow/MapReadToNodeOperator.java b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/dataflow/MapReadToNodeOperator.java
index 9d0a3c7..46a92ec 100644
--- a/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/dataflow/MapReadToNodeOperator.java
+++ b/genomix/genomix-hyracks/src/main/java/edu/uci/ics/genomix/hyracks/dataflow/MapReadToNodeOperator.java
@@ -4,9 +4,9 @@
 import java.nio.ByteBuffer;
 
 import edu.uci.ics.genomix.hyracks.data.primitive.NodeReference;
-import edu.uci.ics.genomix.hyracks.data.primitive.PositionListReference;
 import edu.uci.ics.genomix.hyracks.data.primitive.PositionReference;
 import edu.uci.ics.genomix.type.KmerBytesWritable;
+import edu.uci.ics.genomix.type.PositionListWritable;
 import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
 import edu.uci.ics.hyracks.api.dataflow.IOperatorNodePushable;
 import edu.uci.ics.hyracks.api.dataflow.value.IRecordDescriptorProvider;
@@ -172,11 +172,11 @@
             }
         }
 
-        private void setPositionList(PositionListReference list, int count, byte[] array, int offset, boolean byRef) {
+        private void setPositionList(PositionListWritable positionListWritable, int count, byte[] array, int offset, boolean byRef) {
             if (byRef) {
-                list.setNewReference(count, array, offset);
+                positionListWritable.setNewReference(count, array, offset);
             } else {
-                list.set(count, array, offset);
+                positionListWritable.set(count, array, offset);
             }
         }