all optimizations are implemented and tested. Parallell implementation added. 8.7 times speedup.