final changes, algorithms working properly