table order

I have added some new functions to code, as option to sort the elements
of training in a specified order. I have also cleaned it a bit just to
make it more readable and faster.