more algorithm improvements