Cleaned up handling of ranks