fixed multiple bugs

-koren-scheme gradp/gradn now correct
-ratio slopes calculated in better way
-tidy_up checks max_id instead of n_used