Improved group assign function. Added if-name-is-main.