Remove hanging comma
Rename SQL functions, greatest->max, ...
do not store bad calculations