convert nth to a function