Initial refactoring so that PipelineStage stores is stage number

See #67.