Optimize functions to add XP and badges