Final clean up of new_sd

All moved inside math.c