speeding up the alignment code