sequence function implementation