Okay. This solution is not elegant, but I think at the moment the best solution, and the algorithm duplicated is easy to understand.