Improve the top group algorithm

Edited by Ghost User