added tests, edge case guards and docs for sequence.R