finished draft of the algorithm
still left to test and optimise the algorithm