Add tests for reference position and fix refpos position off-by-one-error