Update math
Add sort
Fix return statement