task4: algorithm improvements