2014-10-15 , version 1

Made the program more abstract.
2014-10-15 , version 2

Very important change, works much better now.
The algorithm used in previous versions were incorrect to p>2.