WIP: refactoring groups javascript. soo messy.