badges.js finished functions, converted mostly from pseudocode