Fix rank function. Closes #34.