1. fix an very big error when counting the user number for each
application;
2. some minor refactors;