Revert and finish

Revert previous commit, add sort equations and fix output