firstSequence working version

have renamed all vars to be meaningful, and tidied up the code so that
it is reasonably coherent