i think it is possible to divide this between threads and do last calculation faster - this going to be a bit faster solution