Implemented ranks, code refactored.