Changed condition in in_groups function for Array + some other code refactoring