Work2.1

Improved the algorithm