#9 implemented new algorithm for full functionality