Adds custom function to remove empty groups

[this is not tested yet. I'll get around to that, I swear]