Updated to reflect API changes.

Also, implemented functionality for arbitrary values of 'n'.