improved some code in lib and fixed bug when user deletes a group