Greatly reworked the algorithms

Also, made the output better and finer.