Rank detection

Based on #48