Added rank-based color selection, cleaned up rank code